#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define pc putchar
#define pb push_back
#define mp make_pair
#define ls (id<<1)
#define rs ((id<<1)|1)
#define mid ((l+r)>>1)
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)

int read(){
    int ret=0,f=0; char ch=gc();
    while(ch<'0'||ch>'9') f|=(ch=='-'),ch=gc();
    while(ch>='0'&&ch<='9') ret=(ret<<1)+(ret<<3)+(ch^48),ch=gc();
    return f?-ret:ret;
}

void write(int x){
    if(!x) return pc('0'),void();
    if(x<0) pc('-'),x=-x;
    int stk[30],tp=0;
    while(x) stk[++tp]=x%10,x/=10;
    while(tp) pc('0'+stk[tp--]);
    return;
}

const int Maxn=1e6+10;
int N,M,Q,xa,ya,xb,yb,fa[Maxn],Ans;
char A[1010][1010];

bool check(int x,int y){
    if(x<xa||x>xb||y<ya||y>yb) return 0;
    if(A[x][y]=='0') return 0;
    return 1;
}

int id(int x,int y){return (x-1)*M+y;}
int find(int x){return fa[x]=(fa[x]==x?x:find(fa[x]));}

void Merge(int a,int b){
    int fu=find(a),fv=find(b);
    if(fu^fv) fa[fv]=fu;
}

void Solve(){
    For(i,1,N) For(j,1,M) fa[id(i,j)]=id(i,j);
    xa=read(),ya=read(),xb=read(),yb=read(),Ans=0;
    For(x,xa,xb){
        For(y,ya,yb){
            if(A[x][y]=='1'){
                if(check(x-1,y)) Merge(id(x-1,y),id(x,y));
                else if(check(x,y-1)) Merge(id(x,y-1),id(x,y));
                else if(check(x+1,y)) Merge(id(x+1,y),id(x,y));
                else if(check(x,y+1)) Merge(id(x,y+1),id(x,y));
            }
        }
    }
    For(x,xa,xb) For(y,ya,yb) 
        if(A[x][y]=='1'&&find(id(x,y))==id(x,y)) ++Ans;
    write(Ans),pc('\n');
}

int main(){
    freopen("unicom.in","r",stdin);
    freopen("unicom.out","w",stdout);
    N=read(),M=read(),Q=read();
    For(i,1,N) scanf("%s",A[i]+1);
    while(Q--) Solve();
    return 0;
}